using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using UWBGL_XNA_Lib10;
using Microsoft.Xna.Framework;

namespace XNA_WCSupport
{
	public partial class XFormInfoControl : UserControl
	{
		UWB_XFormInfo mXFormInfo;
		float mTranslationMin;
		float mTranslationMax;
		float mScaleMin;
		float mScaleMax;
		float mRotationMin;
		float mRotationMax;

		public XFormInfoControl()
		{
			InitializeComponent();

			mTranslationMin = -10;
			mTranslationMax = 10;
			mScaleMin = .1f;
			mScaleMax = 10;
			mRotationMin = -180;
			mRotationMax = 180;

			mXFormInfo = Program.getModel().getModelTransform();
			initializeSliders();
		}

		public void setSliderRange(float tmin, float tmax, float smin, float smax, float rmin, float rmax)
		{
			mTranslationMin = tmin;
			mTranslationMax = tmax;
			mScaleMin = smin;
			mScaleMax = smax;
			mRotationMin = rmin;
			mRotationMax = rmax;
		}

		public void initializeSliders()
		{
			if (radioTranslate.Checked)
			{
				sliderX.ChangeRangeValues(mTranslationMin, mTranslationMax, mXFormInfo.getTranslation().X);
				sliderY.ChangeRangeValues(mTranslationMin, mTranslationMax, mXFormInfo.getTranslation().Y);
				sliderY.Enabled = true;
			}
			else if (radioScale.Checked)
			{
				sliderX.ChangeRangeValues(mScaleMin, mScaleMax, mXFormInfo.getScale().X);
				sliderY.ChangeRangeValues(mScaleMin, mScaleMax, mXFormInfo.getScale().Y);
				sliderY.Enabled = true;
			}
			else if (radioRotate.Checked)
			{
				sliderX.ChangeRangeValues(mRotationMin, mRotationMax, mXFormInfo.getRotationInDegrees());
				sliderY.ChangeRangeValues(mRotationMin, mRotationMax, 0);
				sliderY.Enabled = false;
			}
			else if (radioPivot.Checked)
			{
				sliderX.ChangeRangeValues(mTranslationMin, mTranslationMax, mXFormInfo.getPivot().X);
				sliderY.ChangeRangeValues(mTranslationMin, mTranslationMax, mXFormInfo.getPivot().Y);
				sliderY.Enabled = true;
			}
		}

		public void notifyModelXFormChange()
		{
			Program.getModel().setModelTransform(mXFormInfo);

		}

		private void radioClicked(object sender, EventArgs e)
		{
			initializeSliders();
		}

		private void sliderScroll(object sender, EventArgs e)
		{
			float x = sliderX.GetSliderValue();
			float y = sliderY.GetSliderValue();

			if (radioTranslate.Checked)
			{
				mXFormInfo.setTranslation(new Vector3(x, y, 0));
			}
			else if (radioScale.Checked)
			{
				mXFormInfo.setScale(new Vector3(x, y, 1));
			}
			else if (radioRotate.Checked)
			{
				mXFormInfo.setRotationDegrees(x);
			}
			else if (radioPivot.Checked)
			{
				mXFormInfo.setPivot(new Vector3(x, y, 0));
			}
		}

		private void buttonReset_Click(object sender, EventArgs e)
		{
			mXFormInfo = new UWB_XFormInfo();
			Program.getModel().setModelTransform(mXFormInfo);
			initializeSliders();
		}
	}
}
